import pandas as pd
import yaml
from yaml import SafeLoader
from datareport.api.DataSource import DataSource
from datareport.api.annotation.Font import Font
from datareport.impl.paragraph.base.BaseParagraph import BaseParagraph
from datareport.api.annotation.Style import style

@style()
class KaiZhanQingKuang_one_content_33(BaseParagraph):
    """
    组织生活开展情况-概括
    """

    def __init__(self):
        super().__init__()
        self.text = '''本年度，各基层党支部制定组织生活计划累计{}场次，累计开展组织生活{}场次，组织生活计划的实际完成度达{}%。'''
        self.fonts=[
            Font(text='本年度，各基层党支部制定组织生活计划累计'),
            Font(text='场次'),
            Font(text='5',superscript=True,size=12),
            Font(text='，累计开展组织生活'),
            Font(text='场次，组织生活计划的'),
            Font(text='实际完成度达',bold=True),
            Font(text='%',bold=True),
            Font(text='6',superscript=True,size=12,bold=True)
        ]
        self.sort = 23
        self.section = 6

    def plot(self, df, plt):
        pass

    def getData(self, result):
        pass

    def start(self, conn, year, plt):
        plan=pd.read_sql('''select count(*) from t_meetingplan where isPlan=1 and completeStatus='通过'
        ''',con=conn)
        plan_num=plan.values[0][0]
        actual=pd.read_sql('''select count(1) from t_meetingrecord where completeStatus='通过'
        ''',con=conn)
        actual_num=actual.values[0][0]
        self.fonts.insert(1,Font(text=str(plan_num)))
        self.fonts.insert(-3,Font(text=str(actual_num)))
        self.fonts.insert(-2,Font(text=str(round(100*actual_num/plan_num,1))))


if __name__ == '__main__':
    with open('D:\work\sanhuiyike\datareport\config.yaml', encoding='utf-8') as f:
        data = yaml.load(f, Loader=SafeLoader)
    con=DataSource(data['datasource']).conn
    KaiZhanQingKuang_one_content().start(con,2023,'')
